<?php defined('SYSPATH') or die('No direct access allowed.');

class Controller_Admin_Auth extends Controller_Template
{
    public $template = "admin/login";
    
    public function action_login()
    {
        $this->template->bind('errors', $errors);
        
        if($_POST)
        {
            if(Auth::instance()->login($_POST['login'], $_POST['password'])){
                $session = Session::instance();
                if($redirect = $session->get('redirect')) {
                    $session->delete('redirect');                
                    Request::$initial->redirect($redirect);
                } else {
                    Request::$initial->redirect('admin/main');
                }
            }
            
            $errors = array('Неверная пара логин/пароль');
            $errors[] = Auth::instance()->hash_password($_POST['password']);
        }
                
    }
    
    public function action_logout()
    {
        Auth::instance()->logout(true);
        Request::$initial->redirect('admin/main');
    }
}